<?php 
/*
**模型：信息模型分类（未来的CMS）
**model/class.cms_cates.php
**By QINIAO
*/

class qicmsCate{
	var $db;
	
	function qicmsCate($dbhandle)
	{
		$this->db = $dbhandle;
	}

	//获取CMS分类列表
	function getcmsCate()
	{
	$res = $this->db->query("select * from ".DB_PREFIX."cms_cates");
	$cmsCates = array();
	while($row = $this->db->fetch_array($res))
	{
	$row['id'] = $row['id'];
	$row['cname'] = $row['cname'];
	$cmsCates[] = $row;
	}
	return $cmsCates;
	}
	
	//获取一条CMS分类的数据
	function getOnecmsCate($cateid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."cms_cates where id=$cateid");
	$row = $this->db->fetch_array($res);
	$cmsCateData = array();
	if($row)
	{
	$cmsCateData = array(
	'id' => $row['id'],
	'cname' => $row['cname']
	);
	}
	return $cmsCateData;
	}
	
	//获取分类名字
	function getcmsCateName($cateid)
	{
	if($cateid > 0)
	{
	$res = $this->db->query("SELECT cname FROM ". DB_PREFIX ."cms_cates WHERE id = $cateid");
	$row = $this->db->fetch_array($res);
	$cmsCateName = htmlspecialchars($row['cname']);
	}else 
	{
	$cmsCateName = '未分类';
	}
	return $cmsCateName;
	}
	
	//添加CMS分类
	function addcmsCate($cname)
	{
	$sql = "insert into ".DB_PREFIX."cms_cates (cname) values ('$cname')";
	$this->db->query($sql);
	}
	
	//更新cms分类
	function updatecmsCate($cmsCateData,$cateid)
	{
	$Item = array();
	foreach($cmsCateData as $key=>$data)
	{
	$Item[] = "$key = '$data'";
	}
	$upStr = implode(',',$Item);
	$this->db->query("update ".DB_PREFIX."cms_cates set $upStr where id=$cateid");
	}
	
	//删除CMS分类
	function deletecmsCate($cateid)
	{
	$this->db->query("delete from ".DB_PREFIX."cms_cates where id=$cateid");
	}
 

	}

?>